package com.xiaohei.rabbitmq.two;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xiaohei.rabbitmq.utils.RabbitmqUtils;

/**
 * @DESCRIPTION: 这是一个工作线程相当于消费者
 * @AUTHOR: 王希辰
 * @DATE: 2022/3/16 16:29
 */
public class Worker01 {
    //队列名称
    public static final String QUEUE_NAME="hello";
    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel= RabbitmqUtils.getChannel();

        DeliverCallback deliverCallback=(consumerTag,message)->{
            System.out.println("接收到的消息："+new String(message.getBody()));
        };

        CancelCallback cancelCallback=consumerTag -> {
            System.out.println("消息被消费者取消消费接口回调逻辑");
        };
        System.out.println("C2_等待接收消息...");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
